package  com.diamond.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.diamond.bo.OrderBO;
import com.diamond.bo.QueryOrderBO;
import com.diamond.bo.ReturnBO;
import com.diamond.bo.SuppOrderBO;
import com.diamond.facade.SupporderFacade;
import com.diamond.util.JsonMSG;
import com.opensymphony.xwork2.ActionSupport;

/**
 * MyorderAction ������
 * @author JSmart Tools
 */
public class SupporderAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9028966652239141934L;
	private static Logger log=LoggerFactory.getLogger(SupporderAction.class);
	private HttpServletRequest request;
	private SupporderFacade supporderFacade;
	private SuppOrderBO suppOrderBo;
	private List<SuppOrderBO> dataList;
	private QueryOrderBO queryOrderBo;
	private OrderBO orderBo;
	private String tips;
	private String json;
	
	public String torder(){
		return SUCCESS;
	}
	
	//-------------------------------------------
/************************************后台方法********************************************/
	public String querySuppOrder() {
//		System.out.println("*****************供应商订单查询********************");
		request = ServletActionContext.getRequest();
		String start = request.getParameter("start");
		String pageSize = request.getParameter("limit");
		if (null == start || "".equals(start) || null == pageSize || "".equals(pageSize)) {
			queryOrderBo.setStart(0);
			queryOrderBo.setPageSize(15);
		} else {
			queryOrderBo.setStart(Integer.valueOf(start));
			queryOrderBo.setPageSize(Integer.valueOf(pageSize));
		}
		try {
			if ("1".equals(queryOrderBo.getOrderType())) {
				ReturnBO<SuppOrderBO> returnBo = supporderFacade.querySuppOrder(queryOrderBo);
				this.json=JsonMSG.sucess(returnBo).toJson();
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.json=JsonMSG.failed("查询失败").toJson();
			log.error("查询异常!",e);
		}
		return "json";
	}
	
	public String querySuppOrderById() {
//		System.out.println("*****************供应商订单明细查询********************");
		try {
			String suppOrdMasterId = json;
			OrderBO orderBo = supporderFacade.querySuppOrderById(suppOrdMasterId);
			this.json = JsonMSG.sucess(orderBo).toJson();
		} catch (Exception e) {
			e.printStackTrace();
			this.json = JsonMSG.failed("查询失败").toJson();
			log.error("查询异常!", e);
		}
		return "json";
	}
	
 
	public String getJson() {
		return json;
	}

	public void setJson(String json) {
		this.json = json;
	}
	
	public void setSupporderFacade(SupporderFacade supporderFacade) {
		this.supporderFacade = supporderFacade;
	}

	public SuppOrderBO getSuppOrderBo() {
		return suppOrderBo;
	}

	public void setSuppOrderBo(SuppOrderBO suppOrderBo) {
		this.suppOrderBo = suppOrderBo;
	}

	public String getTips() {
		return tips;
	}

	public void setTips(String tips) {
		this.tips = tips;
	}

	public OrderBO getOrderBo() {
		return orderBo;
	}

	public void setOrderBo(OrderBO orderBo) {
		this.orderBo = orderBo;
	}

	public List<SuppOrderBO> getDataList() {
		return dataList;
	}

	public void setDataList(List<SuppOrderBO> dataList) {
		this.dataList = dataList;
	}

	public QueryOrderBO getQueryOrderBo() {
		return queryOrderBo;
	}

	public void setQueryOrderBo(QueryOrderBO queryOrderBo) {
		this.queryOrderBo = queryOrderBo;
	}
}
